package com.vunguyen.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.vunguyen.model.Phieubaonghi;

public class PDFBuilder extends AbstractITextPdfView {

	@SuppressWarnings("unchecked")
	@Override
	protected void buildPdfDocument(Map<String, Object> model,
			Document document, PdfWriter writer, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		//File fontFile = new File("resources/font/arialuni.ttf");
		String font_vn = "vuArial.ttf";
		List<Phieubaonghi> listPhieuBaoNghi = (List<Phieubaonghi>) model.get("listPhieuBaoNghi");

		
		PdfPTable table = new PdfPTable(7);
        table.setWidthPercentage(100.0f);
        table.setWidths(new float[] {3.0f, 2.0f, 2.0f, 2.0f, 1.0f, 2.0f, 2.0f});
        table.setSpacingBefore(10);
   
         
        // define font for table header row
//        Font font = FontFactory.getFont(FontFactory.defaultEncoding);
//        font.setColor(BaseColor.WHITE);
//        
        BaseFont base = BaseFont.createFont(font_vn, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
       // BaseFont base = BaseFont.createFont("KozMinPro-Regular", "UniJIS-UCS2-H", BaseFont.NOT_EMBEDDED);
        Font font = new Font(base, 12, Font.NORMAL);
		document.add(new Paragraph("Tiết nhận hàng",font));
        // define table header cell
        PdfPCell cell = new PdfPCell();
        cell.setBackgroundColor(BaseColor.BLUE);
        cell.setPadding(5);
        
        
        // write table header
        cell.setPhrase(new Phrase("Tuần", font));
        table.addCell(String.valueOf(listPhieuBaoNghi.getClass()));
         
        cell.setPhrase(new Phrase("Ngày", font));
        table.addCell(cell);
       
 
        cell.setPhrase(new Phrase("Môn học", font));
        table.addCell(cell);
         
        cell.setPhrase(new Phrase("Tiết", font));
        table.addCell(cell);
         
        cell.setPhrase(new Phrase("Số tiết", font));
        table.addCell(cell);
        
        cell.setPhrase(new Phrase("Lý do", font));
        table.addCell(cell);
        
        cell.setPhrase(new Phrase("Xác nhận", font));
        table.addCell(cell);
        
        
        
        
        for (Phieubaonghi pbn : listPhieuBaoNghi) {
        
            table.addCell(String.valueOf(pbn.getPhieudangky().getTuan()));
            table.addCell(String.valueOf(pbn.getPhieudangky().getNgay()));
            table.addCell(String.valueOf(pbn.getMonHoc()));
            table.addCell(String.valueOf(pbn.getPhieudangky().getTiet()));
            table.addCell(String.valueOf(pbn.getPhieudangky().getSoTiet()));
            table.addCell(String.valueOf(pbn.getPhieudangky().getLyDo()));
            table.addCell(String.valueOf(pbn.getPhieudangky().getXacNhan()));
            System.out.println(pbn.getPhieudangky().getLyDo());
           

        }
        
        document.add(table);
		
		
		
        
	}

}
